#include <iostream>
#include <vector>
using namespace std;
void sort(vector<int>& arr)
{
	int l = -1, r = arr.size();
	while (l < r) {
		do l++; while (arr[l] < 0);
		do r--; while (arr[r] > 0);
		if (l < r) {
			swap(arr[l], arr[r]);
			cout << endl;
            for (int i = 0; i < arr.size(); ++i) {
        		if (i) cout << ' ';
        		cout << arr[i];
        	}
		}
	}
}
int main()
{
	int n; cin >> n;
	vector<int> arr(n);
	for (auto& e : arr) cin >> e;
	for (int i = 0; i < n; ++i) {
		if (i) cout << ' ';
		cout << arr[i];
	}	cout << endl;
	sort(arr);
	return 0;
}